using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Diagnostics;

namespace BPMN.MainWindow
{
    public abstract class FlowObject:Figure
    {
        public HotSpots objects = new HotSpots();
        FlowObjectList flowObjects = new FlowObjectList();
        List<ConnectingObject> links = new List<ConnectingObject>();
        public abstract void updateHotSpots();
        public void updateLocation(PointF offset)
        {
            foreach (FlowObject flowObject in flowObjects)
            {
                updateLocation(offset);
            }
            foreach (HotSpot hotSpot in objects)
            {
                hotSpot.Location=new PointF(hotSpot.Location.X+offset.X,hotSpot.Location.Y+offset.Y);
            }
            this.Location = new PointF(this.Location.X+offset.X ,this.Location.Y +offset.Y);
            PointF LocationBoundingBox = new PointF(Location.X - Size.Width / 2, Location.Y - Size.Height / 2);
            SizeF SizeBoundingBox = new SizeF(Size.Height, Size.Width);
            BoundingBox = new RectangleF(LocationBoundingBox, SizeBoundingBox);
           // this.BoundingBox=new RectangleF(this.Location,this.Size);
        }
        public bool Contains(PointF point)
        {
            return Region.IsVisible(point);
        }
    }
    public class FlowObjectList : IEnumerable<FlowObject>
    {

        List<FlowObject> FlowObjects = new List<FlowObject>();

        public FlowObject this[int index]
        {
            get
            {
                return FlowObjects[index];
            }
            set
            {
                FlowObjects[index] = value;
            }
        }

        public FlowObject this[string name]
        {
            get
            {
                for (int i = 0; i < FlowObjects.Count; i++)
                {
                    if (FlowObjects[i].Name == name)
                    {
                        return FlowObjects[i];
                    }
                }
                return null;
            }
            set
            {
                for (int i = 0; i < FlowObjects.Count; i++)
                {
                    if (FlowObjects[i].Name == name)
                    {
                        FlowObjects[i] = value;
                    }
                }
            }
        }

        public int Count
        {
            get
            {
                return FlowObjects.Count;
            }
        }

        public void Add(FlowObject item)
        {
            FlowObjects.Add(item);
        }

        public void Clear()
        {
            FlowObjects.Clear();
        }

        public int GetIndex(string name)
        {
            for (int i = 0; i < FlowObjects.Count; i++)
            {
                if (FlowObjects[i].Name == name)
                {
                    return i;
                }
            }
            return -1;
        }

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return FlowObjects.GetEnumerator();
        }

        #endregion

        #region IEnumerable<FlowObject> Members

        public IEnumerator<FlowObject> GetEnumerator()
        {
            return FlowObjects.GetEnumerator();
        }

        #endregion
    }
}
